
package frsf.cidisi.faia.designer;

import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class CellGUI extends JPanel implements MouseListener {
    
    private TableGUI table;
    private ImageIcon back;
    private int type;
    private int [] markedCell = new int[2];
    
    public CellGUI() {        
        // este constructor no se usar&aacute;, se deja para poder crear el bean.        
    }
    
    public CellGUI(TableGUI t) {
        initComponents();        
        this.table = t;
        if(this.table.isTypeTable() == true){// tablero responde a clics?
            this.addMouseListener(this);
        }
    }
    
    public void setBack(ImageIcon back){
        this.back = back;
    }
    
    public ImageIcon getBack(){        
        return this.back;
    }
    
    public int getType(){
        return type;
    }
    
    public void setType(int i){
        type = i;
    }
                          
    private void initComponents() {
        type = 0;
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 4, Short.MAX_VALUE)
        );
        
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 4, Short.MAX_VALUE)
        );
    }                       
    
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        g.drawImage(back.getImage(), 0,0,this.getWidth(),this.getHeight(),this);
    }
    
    public void mouseClicked(MouseEvent e){}
    public void mouseEntered(MouseEvent e){}
    public void mouseExited(MouseEvent e){}
    
    public void mousePressed(MouseEvent e)
    {
            this.setMarkedCell(table.getCoordinates((CellGUI)e.getComponent())); 
            this.table.paint(this.getMarkedCell()[0],this.getMarkedCell()[1]);
    }
    
    public void mouseReleased(MouseEvent e){}
    
    public int[] getMarkedCell() {
        return markedCell;
    }
    
    public void setMarkedCell(int[] cell) {
        this.markedCell = cell;
    }    
}
